<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: product_reviews.php 200 2013-09-22 07:58:43Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 200 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-22 07:58:43 +0000 (Sun, 22 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

include ('includes/application_top.php');

$smarty = new Smarty;

require(DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/source/boxes.php');
require_once(DIR_FS_INC.'inc.row_number_format.php');
require_once(DIR_FS_INC.'inc.date_short.php');
require_once(DIR_FS_INC.'inc.get_url_friendly_text.php');

$get_params = get_all_get_params();
$get_params_back = get_all_get_params(array('reviews_id'));
$get_params = substr($get_params, 0, -1);
if (not_null($get_params_back))
	$get_params_back = substr($get_params_back, 0, -1);
else
	$get_params_back = $get_params;

$product_info = $db->db_query("SELECT 
									pd.products_name 
								FROM 
									".TABLE_PRODUCTS_DESCRIPTION." pd 
									LEFT JOIN ".TABLE_PRODUCTS." p 
										ON pd.products_id = p.products_id 
								WHERE 
									pd.language_id = '".(int)$_SESSION['languages_id']."' 
								AND 
									p.products_status = '1' 
								AND 
									pd.products_id = '".(int)$_GET['products_id']."'");
if(!$product_info->_numOfRows)
	redirect(href_link(FILENAME_REVIEWS));

$breadcrumb->add(NAVBAR_TITLE_PRODUCT_REVIEWS, href_link(FILENAME_PRODUCT_REVIEWS, $get_params));

require (DIR_WS_INCLUDES.'header.php');

$smarty->assign('PRODUCTS_NAME', $product_info->fields['products_name']);

$data_reviews = array ();
$reviews = $db->db_query("SELECT 
								reviews_rating, 
								reviews_id, 
								customers_name, 
								date_added, 
								last_modified, 
								reviews_read 
							FROM 
								".TABLE_REVIEWS." 
							WHERE 
								products_id = '".(int)$_GET['products_id']."' 
							ORDER BY 
								reviews_id DESC");
								
if($reviews->_numOfRows) {
	
	$row = 0;
	while (!$reviews->EOF) {
		$row ++;
		if(MODULE_SEO_URL_INDEX_STATUS == 'True')
			$link = 'review-'.$reviews->fields['reviews_id'].'/'.get_url_friendly_text($product_info->fields['products_name']).'.html';
		else
			$link = href_link(FILENAME_PRODUCT_REVIEWS_INFO, 'reviews_id='.$reviews->fields['reviews_id']);
			
		$data_reviews[] = array('ID' => $reviews->fields['reviews_id'], 
								'AUTHOR' => '<a href="'.$link.'">'.$reviews->fields['customers_name'].'</a>', 
								'DATE' => date_short($reviews->fields['date_added']), 
								'RATING' => image('templates/'.CURRENT_TEMPLATE.'/img/stars_'.$reviews->fields['reviews_rating'].'.png', sprintf(BOX_REVIEWS_TEXT_OF_5_STARS, $reviews->fields['reviews_rating'])), 
								'TEXT' => $reviews->fields['reviews_text']);
		$reviews->MoveNext();
	}
}
$smarty->assign('module_content', $data_reviews);
$smarty->assign('BUTTON_BACK', '<a href="'.href_link(FILENAME_PRODUCT_INFO, $get_params_back).'">'.image_button('button_back.gif', IMAGE_BUTTON_BACK).'</a>');

$smarty->assign('language', $_SESSION['language']);

if(!CacheCheck()) {
	$smarty->caching = false;
	$main_content = $smarty->fetch(CURRENT_TEMPLATE.'/module/product_reviews.html');
} else {
	$smarty->caching = true;
	$smarty->cache_lifetime = CACHE_LIFETIME;
	$smarty->cache_modified_check = CACHE_CHECK;
	$cache_id = $_SESSION['language'].$_GET['products_id'];
	$main_content = $smarty->fetch(CURRENT_TEMPLATE.'/module/product_reviews.html', $cache_id);
}

$smarty->assign('language', $_SESSION['language']);
$smarty->assign('main_content', $main_content);
$smarty->caching = false;
if(!defined('RM'))
	$smarty->loadFilter('output', 'note');
$smarty->loadFilter('output','trimwhitespace');
$smarty->display(CURRENT_TEMPLATE.'/index.html');
include ('includes/application_bottom.php');
?>